﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace HlslCompiler
{
    static public class FeedbackParser
    {

        static public List<Feedback> Parse(string message)
        {
            var list = new List<Feedback>();
            foreach (var line in message.Split('\n'))
            {
                if (!string.IsNullOrWhiteSpace(line))
                    list.Add(ParseLine(line));
            }
            return list;
        }

        static private Feedback ParseLine(string line)
        {
            var regex = new Regex(@"\((?<row>\d+),(?<column>\d+)\):(?<message>.*)$");
            var result = regex.Match(line);
            if (result.Success)
            {
                return new Feedback()
                {
                    Column = int.Parse(result.Groups["column"].Value),
                    Row = int.Parse(result.Groups["row"].Value),
                    Message = result.Groups["message"].Value.Trim()
                };
            }
            return new Feedback() { Message = line };
        }

    }
}
